#include<bits/stdc++.h>
using namespace std;
struct range
{
  int from,to;
}a[10000];
 bool cmp(range x,range y)
 {
     return x.to<y.to;
 }
 int main()
 {
     int n,i,sum=0;
     cin>>n;
     for(i=0;i<n;i++)
        cin>>a[i].from>>a[i].to;
     sort(a,a+n,cmp);
     int x;
     for(i=0,x=-1;i<n;i++)
     {
 
         if(x>=a[i].from)
			 	continue;
         x=a[i].to;
         sum++;        
     }
     cout<<sum;
     return 0;
 }

